package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("adminDishController")
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;
    /**
     * 新增菜品
     */
    @PostMapping
    @ApiOperation(value = "新增菜品")
    public Result add(@RequestBody DishDTO dishDTO){
    log.info("新增菜品:{}",dishDTO);
        return dishService.add(dishDTO);
    }
    /**
     * 查询分页
     */
    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    public Result page(DishPageQueryDTO dto){
        log.info("分页查询：{}", dto);
    return dishService.page(dto);
    }
    /**
     * 删除数据
     */
    @DeleteMapping
    @ApiOperation(value = "删除数据")
    public Result delete(@RequestParam List<Long> ids){
        log.info("菜品批量删除：{}", ids);
        return dishService.delete(ids);
    }
    /**
     * 根据id查询菜品
     */
    @ApiOperation(value = "根据id查询菜品")
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id){
        log.info("查询：{}", id);
        return dishService.getById(id);
    }
    /**
     * 套餐需求根据分类id查询菜品
     */
    @ApiOperation(value = "根据分类id查询菜品")
    @GetMapping("/list")
    public Result list(Long categoryId){
        log.info("查询：{}", categoryId);
        return dishService.list(categoryId);
    }
    /**
     * 修改菜品
     */
    @ApiOperation(value = "修改菜品")
    @PutMapping
    public Result update(@RequestBody DishDTO dishDTO){
        log.info("修改菜品：{}", dishDTO);
        return dishService.update(dishDTO);
    }
    /**
     * 状态设置
     */
    @ApiOperation(value = "修改启用状态")
    @PostMapping("/status/{status}")
    public Result updatestatus(@PathVariable Integer status, Long id){
        return dishService.updatestatus(status,id);
    }
}
